﻿// JScript 文件
//添加Application
var rowcountApp="-1";     //行号与列号
var peoplenum="-1"
function AddRowApplication()
{
    if(rowcountApp=="-1")
        rowcountApp=document.getElementById("appcount").value
    if(peoplenum=="-1")
        peoplenum=document.getElementById("txbpeoplenum").value;
	oldhtml=document.getElementById("application").innerHTML;
	oldhtml+='<table width="100%" border="1" cellspacing="0" style="border-top:none; border-bottom:none; border-left:none; border-right:none"  id="AppNode'+rowcountApp+'">';
	oldhtml+='<tr>'
    oldhtml+='<td width="56px" height="50"><input type="text" name="txbapplytitle'+rowcountApp+'" style="width:90%" class="UnderlineButton1"></td>'
    oldhtml+='<td width="58px"><input type="text" name="txbname' + rowcountApp + '" style="width:90%" class="UnderlineButton1"></td>';
    oldhtml+='<td width="59px"><select name="ddlmarry' + rowcountApp + '"><option>已婚</option><option>未婚</option></select></td>';
    oldhtml+='<td width="212px"><input type="text" name="txbunit' + rowcountApp + '" style="width:90%" class="UnderlineButton1"></td>';
    oldhtml+='<td width="214px"><input type="text" name="txbcard' + rowcountApp + '" style="width:90%" class="UnderlineButton1"></td>';
    oldhtml+='<td width="168px"><input type="text" name="txbincome' + rowcountApp + '" style="width:90%" class="UnderlineButton1" onblur="Totleincome(\'txbincome'+rowcountApp+'\',\'text_val'+rowcountApp+'\')" onkeydown = "DigitInput(this,event);"><input type="hidden" id="text_val'+rowcountApp+'" value="0" /></td>';
	oldhtml+='<td width="72px">&nbsp;&nbsp;<input type="checkbox" id="ckbispro' + rowcountApp + '" name="ckbispro' + rowcountApp + '" onclick="CountIsproNum(\'ckbispro' + rowcountApp + '\')"></td>';
	oldhtml+='<td width="38px"><input type="button" value="删除" name="del'+rowcountApp+'" onclick="DelRowApplication('+rowcountApp+');"/></td></tr>';
	oldhtml+='</table>';
    document.getElementById("application").innerHTML=oldhtml;
	rowcountApp++;
	peoplenum++;
}
function DelRowApplication(row)
{
    if(rowcountApp=="-1")
        rowcountApp=document.getElementById("rowcountApp").value
    if(peoplenum=="-1")
        peoplenum=document.getElementById("txbpeoplenum").value;
    peoplenum--;
    TotleincomeAfterDel("txbincome"+row);
    var node = document.getElementById("AppNode"+row)
    var obj = node.childNodes;
    while(node.firstChild!=null)
    {
        node.removeChild(node.firstChild);
    }
    getTotal();
}


//添加Housing
var rowcount="-1";     //行号与列号
var mmm="-1";
function AddRowHousing()
{
    if(rowcount=="-1")
        rowcount=document.getElementById("housecount").value
    if(mmm=="-1")
        mmm=document.getElementById("mmmm").value;
	oldhtml=document.getElementById("houses").innerHTML;
	oldhtml+='<table width="100%" border="1" cellspacing="0"  style="border-top:none; border-bottom:none; border-left:none; border-right:none" id="HousingNode'+rowcount+'">';
	oldhtml+='<tr>'
    oldhtml+='<td width="25px" style="height: 37px">'+mmm+'&nbsp;</td>'
    oldhtml+='<td style="width:175px;height:37px;"><input type="text" name="txblocal' + rowcount + '" class="UnderlineButton1"  style="width:150px"></td>'
    oldhtml+='<td style="height:37px;width:80px;"><input type="text" name="txbarea' + rowcount + '" id="txbarea' + rowcount + '" class="UnderlineButton1" style="width:45px" onblur="OnlyNumber(\'txbarea'+rowcount+'\',\'建筑面积\')"></td>';
	oldhtml+='<td style="height: 37px; width: 87px;"><input type="text" name="txbowner' + rowcount + '" class="UnderlineButton1" style="width:60px"></td>';
	oldhtml+='<td style="width: 129px; height: 37px;"><input type="text" name="txbownproof' + rowcount + '" class="UnderlineButton1" style="width:100px"></td>';
	oldhtml+='<td style="width: 149px; height: 37px;"><input type="text" name="txbnature' + rowcount + '" class="UnderlineButton1" style="width:100px"></td>';
	oldhtml+='<td style="width: 161px; height: 37px;"><input type="text" name="txbremark' + rowcount + '" class="UnderlineButton1" style="width:150px"></td>';
	oldhtml+='<td style="width: 78px; height: 37px;"><input type="checkbox" name="ckbaddcount' + rowcount + '" onclick="getTotal()"></td>';
	oldhtml+='<td style="width: 42px; height: 37px;"><input type="button" value="删除" name="del'+rowcount+'" onclick="DelRowHousing('+rowcount+');"/></td>';
	oldhtml+='</tr>';
	oldhtml+='</table>';
    document.getElementById("houses").innerHTML=oldhtml;
	rowcount++;
	mmm++;
}

function DelRowHousing(row)
{
    //TotleincomeAfterDel("txbincome"+row);
    var node = document.getElementById("HousingNode"+row)
    var obj = node.childNodes;
    while(node.firstChild!=null)
    {
        node.removeChild(node.firstChild);
    }
    getTotal();
   
}
var ispronum=-1;
//统计保障人口数
function CountIsproNum(str)
{
    if(document.getElementById(str).checked==true)
        ispronum++;
    else
        ispronum--;
}
//验证是否为空
function   Check()   
{  
    if(document.form1.txbaddress.value=="")   
    {   
      alert("户籍地址不能为空!"); 
      return   false;   
    }
    for(i=0;i<10;i++)
    if(document.form1.txbname.value=="")   
    {   
      alert("申请人姓名不能为空!"); 
      return   false;
    }   
    if(document.form1.txbcard.value=="")   
    {   
      alert("申请人身份证号码不能为空!"); 
      return   false;   
    }
    if(document.form1.txbincome.value=="")   
    {   
      alert("申请人前12个月收入不能为空!"); 
      return   false;   
    }
    if(document.form1.txbapplytime.value=="")   
    {   
      alert("申请时间不能为空!"); 
      return   false;   
    }
    var result=false;
    var opts = document.all("rbldoc");
    if(opts)   
    {   
        for(var i = 0; i < opts.length; i++)   
        {   
            if (opts[i].checked)   
            {      
                result=true;
                break;   
            }   
        }   
    }
    if(result==false)
    {
         alert('请选择证件材料');
         return false;
    }
    if(mess!="")
    {
        alert(mess);
        return false;
    }
    return true;
}

//收入合计
var totleincome="-1";
function Totleincome(str,str2)
{
    if(rowcountApp=="-1")
        rowcountApp=document.getElementById("rowcountApp").value
    if(peoplenum=="-1")
        peoplenum=document.getElementById("txbpeoplenum").value;
    totleincome=document.getElementById("txbtotleincome").value;  
    if(document.getElementById(str2).value!=document.getElementById(str).value)
    {
        if(document.getElementById(str).value=="")
            document.getElementById(str).value="0";
        totleincome-=parseInt(document.getElementById(str2).value,10);
        totleincome+=parseInt(document.getElementById(str).value,10);
        document.getElementById(str2).value=document.getElementById(str).value;
    }
    else
       return;
    document.getElementById("txbtotleincome").value=totleincome;
    document.getElementById("txbpeoplenum").value=peoplenum;
    document.getElementById("txbavgincome").value=totleincome/peoplenum;
    document.getElementById("txbavgmonthincome").value=document.getElementById("txbavgincome").value/12; 
}

function TotleincomeAfterDel(str)
{
    if(totleincome=="-1")
        totleincome=document.getElementById("txbtotleincome").value;
    if(document.getElementById(str).value!="" && document.getElementById(str).value!="0")
    {
        totleincome-=parseInt(document.getElementById(str).value,10);
        document.getElementById("txbtotleincome").value=totleincome;
    }
    document.getElementById("txbtotleincome").value=totleincome;
    document.getElementById("txbpeoplenum").value=peoplenum;
    document.getElementById("txbavgincome").value=totleincome/peoplenum;
    document.getElementById("txbavgmonthincome").value=document.getElementById("txbavgincome").value/12; 
}
//财产合计

function TotleMoney(str,str2)
{
    var totlemoney=document.getElementById("txbtotleproperty").value;
    if(document.getElementById(str2).value!=document.getElementById(str).value)
    {
        if(document.getElementById(str).value==""||isNaN(document.getElementById(str).value))
            document.getElementById(str).value="0";
        totlemoney-=parseInt(document.getElementById(str2).value,10);
        totlemoney+=parseInt(document.getElementById(str).value,10);
        document.getElementById(str2).value=document.getElementById(str).value;
    }
    else
       return;
    document.getElementById("txbtotleproperty").value=totlemoney;
} 


//房产面积合计
function getTotal()
{
	var totlearea=0;
	arr=new Array();
	//arr[0]=document.getElementById("txbarea0").value;
	for(i=0;i<20;i++)
	{
		if(document.getElementById('txbarea'+i))
		{
			arr[i]=document.getElementById('txbarea'+i).value;
		}
	}
	//if(document.getElementById("ckbaddcount0").checked==true)
	//	totlearea+=parseInt(arr[0]);
	for(i=0;i<arr.length;i++)
	{
		if(document.getElementById("ckbaddcount"+i).checked==true)
			totlearea+=parseInt(arr[i]);	
	}
	var pepnum=document.getElementById("txbpeoplenum").value;
	document.getElementById("txbtotlearea").value=totlearea;
    document.getElementById("txbavgarea").value=totlearea/pepnum;	
	
}


//只能是数字验证
function DigitInput(el,ev) {
    var event = ev || window.event;                 
    var currentKey = event.charCode||event.keyCode;      
    
    //小数点处理
    if (currentKey == 110 || currentKey == 190) {
        if (el.value.indexOf(".")>=0) 
            if (window.event)                       
                event.returnValue=false;      
            else                                    
                event.preventDefault();

    } else 
        if (currentKey!=8 && currentKey != 46 && (currentKey<37 || currentKey>40) && (currentKey<48 || currentKey>57) && (currentKey<96 || currentKey>105))
            if (window.event)                       //IE
                event.returnValue=false;                
            else                                    //火狐
                event.preventDefault();

}

function OnlyNumber(str,str2)
{
    if   (!isNaN(document.getElementById(str).value))
    {   
        return true;
    }   
    else
    {   
        alert(str2+"只能为数字..."); 
        document.getElementById(str).focus();
        return   false;   
    }   
}   

//证件号处显示证件所属类型
var doctype="";
function   ShowDocTpye()   
{   
    var opts = document.all("rbldoc");
    if(opts)   
    {   
        for(var i = 0; i < opts.length; i++)   
        {   
            if (opts[i].checked)   
            {      
                document.getElementById("show").innerHTML=opts[i].value;
                doctype=opts[i].value;
                break;   
            }   
        }   
     }   
}
//添加保障类型点击事件
var otherrentstandard  //租金补贴标准(最低收入、其他家庭)
var lowrentstandard      //租金补贴标准(低收入)
var onlyonearea             //租金补贴户面积（36㎡）
var homeavgarea            //租金补贴比较面积(18㎡)
var standardlowarea      //保障面积最低标准(5㎡)
var subarea
var submoney
var mess=""
function Subsidy()
{
    if(ispronum=-1)
    { 
        ispronum=1;
        for(i=0;i<10;i++)
        {
            if(document.getElementById("ckbispro"+i))
            {
                if(document.getElementById("ckbispro"+i).checked=true)
                   ispronum++;                   
            }
        }
    }
    //alert(ispronum);
    if(document.getElementById("show").innerHTML!="" && doctype=="")
        doctype=document.getElementById("show").innerHTML;
    var inhtml;
    totlearea=document.getElementById("txbtotlearea").value;
    otherrentstandard=document.getElementById("otherrentstandard").value  //租金补贴标准(最低收入、其他家庭)
    lowrentstandard=document.getElementById("lowrentstandard").value      //租金补贴标准(低收入)
    onlyonearea=document.getElementById("onlyonearea").value             //租金补贴户面积（36㎡）
    
    homeavgarea=document.getElementById("homeavgarea").value              //租金补贴比较面积(18㎡)
    standardlowarea=document.getElementById("standardlowarea").value      //保障面积最低标准(5㎡)
    subarea=0;
    submoney=0;
    if(document.getElementById("ckbsubsidy").checked==true)
    {
    //alert("peoplenum:"+peoplenum);
    peoplenum=document.getElementById("txbpeoplenum").value;
        //alert("peoplenum2:"+peoplenum);
        //alert("homeavgarea:"+homeavgarea);
        //alert("totlearea:"+totlearea);
        if (peoplenum==1)
        {
            subarea=onlyonearea-totlearea;
            if (subarea>0&&subarea<5)
                subarea= 5;
            if (subarea<0)
            {
                inhtml='住房面积合计不符合廉租住房租金补贴条件';
                mess="住房面积合计不符合廉租住房租金补贴条件";                
                document.getElementById("subsidy").innerHTML=inhtml;
                return;   
            }
        }
        else
        {
            //peoplenum=document.getElementById("txbpeoplenum").value;
            subarea=ispronum*homeavgarea-((totlearea/peoplenum)*ispronum);
    //alert("subarea:"+subarea);
            if (subarea>0&&subarea<5)
                subarea=5;
            if (subarea<0)
            {
                inhtml='住房面积合计不符合廉租住房租金补贴条件';
                mess="住房面积合计不符合廉租住房租金补贴条件";
                document.getElementById("subsidy").innerHTML=inhtml;
                return;  
            }
        }
        if (doctype=="最低收入家庭"||doctype=="其他家庭")
            submoney=subarea*otherrentstandard;
        else if(doctype=="低收入家庭")
            submoney=subarea*lowrentstandard;
        else
        {
            inhtml='<span style="color:red">未选择相关证件材料</span>';
            document.getElementById("subsidy").innerHTML=inhtml;
            mess="未选择相关证件材料";
            return;  
        }
        document.getElementById("submoney").value=submoney;
        document.getElementById("subarea").value=subarea;
        inhtml='补贴建筑面积为'+ispronum+'*'+homeavgarea+'-('+totlearea+'/'+peoplenum+')*'+ispronum+'=<span style="color:red;font-size:14px">'+subarea+'</span>平方米<br/>';
        inhtml+='月补贴金额为<span style="color:red;font-size:14px">'+submoney+'</span>元';
        document.getElementById("subsidy").innerHTML=inhtml;
    }
    else
    {    
        document.getElementById("subsidy").innerHTML="";
        mess="";
    }
}
function Reduce(obj)
{
    if(obj.checked==true)
        document.getElementById("reduce").className='disinline';
    else
        document.getElementById("reduce").className='disnone'; 
}
function Kind()
{
    if(document.getElementById("ckbkind").checked==true)
    {
        var inhtml='房屋座落：<input type="text" name="houseaddress" class="UnderlineButton1"><br/>';
        inhtml+='建筑面积：<input type="text" name="housearea" class="UnderlineButton1"><br/>';
        inhtml+='使用面积：<input type="text" name="usearea" class="UnderlineButton1"><br/>';
        document.getElementById("kind").innerHTML=inhtml;
    }
    else
        document.getElementById("kind").innerHTML="";
}

function updateHTML()
{
    document.getElementById('historyhtmlInput').value="";
    document.getElementById('historyhtmlInput').value=document.getElementById("cdiv").innerHTML;
}